package com.xxjh.brs.ftp.common.api.result;

import com.xxjh.brs.ftp.common.api.enums.ResponseStatus;
import lombok.Data;

import java.io.Serializable;

/**
 * @author CHENCHEN
 * @title a
 * @company 新兴际华科技（天津）有限公司
 * @create 2024-07-03 19:21
 */
@Data
public class CommonResponse<T>  implements Serializable {

    /** 错误码 */
    private Integer code;

    /** 错误消息 */
    private String message;

    /** 响应数据 */
    private T data;

    public CommonResponse(ResponseStatus status) {
        this.code = status.getCode();
        this.message = status.getMessage();
    }

    public CommonResponse(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public CommonResponse(ResponseStatus status, T data) {
        this.code = status.getCode();
        this.message = status.getMessage();
        this.data = data;
    }

    //成功——无返回数据
    public static CommonResponse SUCCESS = new CommonResponse(ResponseStatus.SUCCESS);

    //成功——有返回数据
    public static CommonResponse SUCCESS(ResponseStatus status, Object data){
        return new CommonResponse<>(status, data);
    }

    //失败——无返回数据
    public static CommonResponse FAIL = new CommonResponse(ResponseStatus.FAILURE);

    //失败——有返回数据
    public static CommonResponse FAIL(ResponseStatus status, Object data){
        return new CommonResponse(status, data);
    }

    //异常——无返回数据
    public static CommonResponse EXCEPTION = new CommonResponse(ResponseStatus.SERVERERROR);

    //异常——无返回数据
    public static CommonResponse EXCEPTION(Integer code, String message){
        return new CommonResponse(code, message);
    }
}
